/*
 * cad_setores.java
 *
 * LICENÇA CC-GNU LGPL
 * 
 * EXCLUSÃO DE GARANTIA 
1.COMO A BIBLIOTECA É LICENCIADA ELA TERÁ TOTAL GARANTIA DE SUPORTE TÉCNICO,
  MAS CASO O CÓDIGO-FONTE SOFRA ALTERAÇÕES, NÃO HAVERÁ NENHUMA GARANTIA PARA A 
  BIBLIOTECA, NO LIMITE PERMITIDO PELA LEI APLICÁVEL. EXCETO QUANDO DE OUTRA FORMA
  ESTABELECIDO POR ESCRITO, OS TITULARES DOS DIREITOS AUTORAIS E/OU OUTRAS PARTES 
  FORNECEM A BIBLIOTECA "NO ESTADO EM QUE SE ENCONTRA", SEM NENHUMA GARANTIA DE 
  QUALQUER TIPO, TANTO EXPRESSA COMO IMPLÍCITA, INCLUINDO, DENTRE OUTRAS, AS GARANTIAS
  IMPLÍCITAS DE COMERCIABILIDADE E ADEQUAÇÃO PARA UMA FINALIDADE ESPECÍFICA. 
  O RISCO INTEGRAL QUANTO À QUALIDADE E DESEMPENHO DA BIBLIOTECA É ASSUMIDO POR VOCÊ.
  CASO A BIBLIOTECA CONTENHA DEFEITOS, VOCÊ ARCARÁ COM OS CUSTOS DE TODOS OS SERVIÇOS,
  REPAROS OU CORREÇÕES NECESSÁRIAS. 

 2.EM NENHUMA CIRCUNSTÂNCIA, A MENOS QUE EXIGIDO PELA LEI APLICÁVEL OU ACORDADO POR 
   ESCRITO, QUALQUER TITULAR DE DIREITOS AUTORAIS OU QUALQUER OUTRA PARTE QUE POSSA 
   MODIFICAR E/OU REDISTRIBUIR A BIBLIOTECA, CONFORME PERMITIDO ACIMA, SERÁ RESPONSÁVEL 
   PARA COM VOCÊ POR DANOS, INCLUINDO ENTRE OUTROS QUAISQUER DANOS GERAIS, ESPECIAIS, 
   FORTUITOS OU EMERGENTES, ADVINDOS DO USO OU IMPOSSIBILIDADE DE USO DA BIBLIOTECA 
   (INCLUINDO, ENTRE OUTROS, PERDA DE DADOS, DADOS SENDO GERADOS DE FORMA IMPRECISA, 
   PERDAS SOFRIDAS POR VOCÊ OU TERCEIROS OU A IMPOSSIBILIDADE DA BIBLIOTECA DE OPERAR 
   COM QUALQUER OUTRO SOFTWARE), MESMO QUE ESSE TITULAR, OU OUTRA PARTE, TENHA SIDO 
   AVISADO SOBRE A POSSIBILIDADE DESSES DANOS.

 * 
 * 
 * 
 * 
 * 
 * 
 * Created on 4 de Novembro de 2008, 19:20
 */

package cadastros;




import java.text.ParseException;
import utilitarios.conexao;
import java.sql.*;
import javax.swing.*;
import java.awt.EventQueue.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
import javax.xml.bind.ParseConversionEvent;
import principal.tela_principal;
import utilitarios.data;



/**
 *
 * @author  Shinigami
 */
public class hd_server extends javax.swing.JFrame {
    
    
    

    public static conexao con_setores,con_hdsf, con_atualiza, con_ordena, con_ordatual;
    public static SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
    String seta_look = "com.birosoft.liquid.LiquidLookAndFeel";
    public static String dataaberto;
    public static java.util.Date dataabt ;
    
    public static int navega = 0; //variavel para saber qual botão foi clicado
    int inicia_combo = 0;
    int modo_banco = 0; //se modo_banco = 1 --> modo salvar
                        //se modo_banco = 2 --> modo alterar
    
    
    
    data mostra_data;
    
    

    
    
    /** Creates new form cad_maquinas */
    public hd_server() {
        initComponents();
        
        
        
        con_setores = new conexao();
        con_setores.conecta();
        
        con_hdsf = new conexao();
        con_hdsf.conecta();
       
        con_atualiza = new conexao();
        con_atualiza.conecta();
        
        con_ordena = new conexao();
        con_ordena.conecta();
        
        con_ordatual = new conexao();
        con_ordatual.conecta();
        
        mostra_data = new data();
        mostra_data.le_data();
        
        
        
        label_data.setText(mostra_data.dia+"/"+mostra_data.mes+"/"+mostra_data.ano);
        
        lb_tecnico.setText(hd_principal.lb_tec.getText()); 
             
       
        lookandfeel();
        travar_campos();
        
        
                    
             
        
        
     
   
    }    
    


    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cd = new javax.swing.ButtonGroup();
        disk = new javax.swing.ButtonGroup();
        usb = new javax.swing.ButtonGroup();
        bt_gravar = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        ta_obs = ta_obs = new JTextArea();
        ta_obs.setDocument( new PlainDocument()  
            {  
                @Override  
                public void insertString( int offs, String str, AttributeSet a )  
                throws BadLocationException  
                {  
                    super.insertString( offs, str.toUpperCase(), a );  
                }  
            } );  ;
            lb_nmaq = new javax.swing.JLabel();
            lb_ip = new javax.swing.JLabel();
            lb_ncall = new javax.swing.JLabel();
            lb_setor = new javax.swing.JLabel();
            lb_tipop = new javax.swing.JLabel();
            label_data = new javax.swing.JLabel();
            bt_primeiro = new javax.swing.JButton();
            bt_anterior = new javax.swing.JButton();
            bt_proximo = new javax.swing.JButton();
            bt_ultimo = new javax.swing.JButton();
            lb_nuser = new javax.swing.JLabel();
            lb_tecnico = new javax.swing.JLabel();
            bt_atender = new javax.swing.JButton();
            lb_status = new javax.swing.JLabel();
            lb_tecresp = new javax.swing.JLabel();
            lb_dataab = new javax.swing.JLabel();
            lb_urg = new javax.swing.JLabel();
            jMenuBar1 = new javax.swing.JMenuBar();
            bt_trocar = new javax.swing.JButton();
            lb_tecabert = new javax.swing.JLabel();
            lb_horaab = new javax.swing.JLabel();
            jMenuBar2 = new javax.swing.JMenuBar();
            jMenu7 = new javax.swing.JMenu();
            jm_salvar = new javax.swing.JMenuItem();
            jm_atend = new javax.swing.JMenuItem();
            jm_troca = new javax.swing.JMenuItem();
            jSeparator2 = new javax.swing.JSeparator();
            jMenuItem2 = new javax.swing.JMenuItem();

            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            setTitle("Fechar Chamado");
            setResizable(false);

            bt_gravar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/mail-forward.png"))); // NOI18N
            bt_gravar.setToolTipText("Fechar Chamado (F2)");
            bt_gravar.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    bt_gravarActionPerformed(evt);
                }
            });

            jLabel8.setText("Descrição:");

            ta_obs.setColumns(20);
            ta_obs.setEditable(false);
            ta_obs.setRows(5);
            jScrollPane2.setViewportView(ta_obs);

            lb_nmaq.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Nome da Máquina", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

            lb_ip.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "IP", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

            lb_ncall.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Nº ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

            lb_setor.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Setor", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

            lb_tipop.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tipo do Problema", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

            label_data.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Data Atual", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

            bt_primeiro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/primeiro_registro.gif"))); // NOI18N
            bt_primeiro.setMnemonic('w');
            bt_primeiro.setToolTipText("Primeiro registro (ALT + W)");
            bt_primeiro.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    bt_primeiroActionPerformed(evt);
                }
            });

            bt_anterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/registro_anterior.gif"))); // NOI18N
            bt_anterior.setMnemonic('a');
            bt_anterior.setToolTipText("Registro anterior (ALT + A)");
            bt_anterior.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    bt_anteriorActionPerformed(evt);
                }
            });

            bt_proximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/proximo_registro.gif"))); // NOI18N
            bt_proximo.setMnemonic('d');
            bt_proximo.setToolTipText("Próximo registro (ALT + D)");
            bt_proximo.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    bt_proximoActionPerformed(evt);
                }
            });

            bt_ultimo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/ultimo_registro.gif"))); // NOI18N
            bt_ultimo.setMnemonic('s');
            bt_ultimo.setToolTipText("Último registro (ALT + S)");
            bt_ultimo.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    bt_ultimoActionPerformed(evt);
                }
            });

            lb_nuser.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Usuário", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

            lb_tecnico.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Técnico", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

            bt_atender.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/icone_telefone.gif"))); // NOI18N
            bt_atender.setToolTipText("Atender Chamado (F3)");
            bt_atender.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    bt_atenderActionPerformed(evt);
                }
            });

            lb_status.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Status", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

            lb_tecresp.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Responsável", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

            lb_dataab.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Data do Chamado", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

            lb_urg.setForeground(new java.awt.Color(204, 0, 0));
            lb_urg.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Urgência", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

            bt_trocar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/gnome-session-switch.png"))); // NOI18N
            bt_trocar.setToolTipText("Trocar Técnico (F4)");
            bt_trocar.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    bt_trocarActionPerformed(evt);
                }
            });

            lb_tecabert.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Aberto por", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

            lb_horaab.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Hora", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 0))); // NOI18N

            jMenu7.setText("Arquivo");

            jm_salvar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F2, 0));
            jm_salvar.setText("Fechar Chamado");
            jm_salvar.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jm_salvarActionPerformed(evt);
                }
            });
            jMenu7.add(jm_salvar);

            jm_atend.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F3, 0));
            jm_atend.setText("Atender Chamado");
            jm_atend.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jm_atendActionPerformed(evt);
                }
            });
            jMenu7.add(jm_atend);

            jm_troca.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, 0));
            jm_troca.setText("Trocar Técnico");
            jm_troca.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jm_trocaActionPerformed1(evt);
                }
            });
            jMenu7.add(jm_troca);
            jMenu7.add(jSeparator2);

            jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F12, 0));
            jMenuItem2.setText("Sair");
            jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jMenuItem1ActionPerformed(evt);
                }
            });
            jMenu7.add(jMenuItem2);

            jMenuBar2.add(jMenu7);

            setJMenuBar(jMenuBar2);

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(27, 27, 27)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(lb_tipop, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                                                .addComponent(lb_setor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(lb_ip, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
                                                .addComponent(lb_nmaq, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                            .addComponent(lb_ncall, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(label_data, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(lb_nuser, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(lb_tecresp, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(lb_status, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(lb_tecnico, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel8)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 353, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(layout.createSequentialGroup()
                                            .addGap(133, 133, 133)
                                            .addComponent(bt_primeiro, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(bt_anterior, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(bt_proximo, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(bt_ultimo, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(bt_trocar, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(bt_atender, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(bt_gravar, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(lb_urg, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lb_tecabert, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(lb_dataab, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lb_horaab, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(lb_ncall, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(label_data, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lb_tecnico, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lb_nuser, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(lb_setor, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(13, 13, 13)
                            .addComponent(lb_tipop, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(lb_nmaq, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lb_ip, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(lb_status, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lb_tecresp, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel8)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(bt_atender, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(bt_gravar, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(bt_primeiro, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(1, 1, 1))
                            .addComponent(bt_anterior, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(bt_proximo, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(bt_ultimo, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(bt_trocar, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lb_horaab, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lb_urg, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lb_tecabert, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE))
                        .addComponent(lb_dataab, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(10, 10, 10))
            );

            java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-552)/2, (screenSize.height-444)/2, 552, 444);
        }// </editor-fold>//GEN-END:initComponents

private void bt_gravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_gravarActionPerformed


    gravar();


    
}//GEN-LAST:event_bt_gravarActionPerformed

private void jm_salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_salvarActionPerformed

    bt_gravarActionPerformed(evt);
    
}//GEN-LAST:event_jm_salvarActionPerformed

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed

    setVisible(false);
    
}//GEN-LAST:event_jMenuItem1ActionPerformed

private void bt_primeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_primeiroActionPerformed
try
        {
           navega = 1;
            hd_principal.con_hdserver.resultset.first();
            mostrar_dados();
                       
         }
        catch(SQLException erro)
        {
            JOptionPane.showMessageDialog(null,"Não localizou dados "+erro);
        }
}//GEN-LAST:event_bt_primeiroActionPerformed

private void bt_anteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_anteriorActionPerformed
try
        {
            if (hd_principal.con_hdserver.resultset.isFirst())
            {
                navega = 1;
            } 
            hd_principal.con_hdserver.resultset.previous();
            mostrar_dados(); 
            
                        
        }
        catch(SQLException erro)
        {
            JOptionPane.showMessageDialog(null,"Não localizou dados "+erro);
        }
}//GEN-LAST:event_bt_anteriorActionPerformed

private void bt_proximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_proximoActionPerformed
try
        {
        if (hd_principal.con_hdserver.resultset.isLast())
            {
                navega = 2;
            }
           hd_principal.con_hdserver.resultset.next();
            mostrar_dados(); 
        }
        catch(SQLException erro)
        {
            JOptionPane.showMessageDialog(null,"Não localizou dados "+erro);
        }
}//GEN-LAST:event_bt_proximoActionPerformed

private void bt_ultimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_ultimoActionPerformed
try
        {
            navega = 2;
            hd_principal.con_hdserver.resultset.last();
            mostrar_dados(); 
            
              
        }
        catch(SQLException erro)
        {
            JOptionPane.showMessageDialog(null,"Não localizou dados "+erro);
        }
}//GEN-LAST:event_bt_ultimoActionPerformed

private void bt_atenderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_atenderActionPerformed

    bt_gravar.setEnabled(true);
    jm_salvar.setEnabled(true);
    lb_status.setText("EM ANDAMENTO");
    
    mostra_data.le_hora();
    lb_horaab.setText(mostra_data.hora );
    
   
    new urgencia().setVisible(true);
    urgencia.lb_codcall.setText(lb_ncall.getText());
    
   
}//GEN-LAST:event_bt_atenderActionPerformed

private void jm_atendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_atendActionPerformed

    bt_atenderActionPerformed(evt);
    
}//GEN-LAST:event_jm_atendActionPerformed

private void bt_trocarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_trocarActionPerformed

    new tecnico().setVisible(true);
    
}//GEN-LAST:event_bt_trocarActionPerformed

private void jm_trocaActionPerformed1(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jm_trocaActionPerformed1

    bt_trocarActionPerformed(evt);
    
}//GEN-LAST:event_jm_trocaActionPerformed1
 
    
     /**
    * @param args the command line arguments
    */
public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new hd_server().setVisible(true);
            }
        });
    }
   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JButton bt_anterior;
    public static javax.swing.JButton bt_atender;
    public static javax.swing.JButton bt_gravar;
    public static javax.swing.JButton bt_primeiro;
    public static javax.swing.JButton bt_proximo;
    public static javax.swing.JButton bt_trocar;
    public static javax.swing.JButton bt_ultimo;
    private javax.swing.ButtonGroup cd;
    private javax.swing.ButtonGroup disk;
    private javax.swing.JLabel jLabel8;
    public static javax.swing.JMenu jMenu7;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator2;
    public static javax.swing.JMenuItem jm_atend;
    public static javax.swing.JMenuItem jm_salvar;
    public static javax.swing.JMenuItem jm_troca;
    public static javax.swing.JLabel label_data;
    public static javax.swing.JLabel lb_dataab;
    public static javax.swing.JLabel lb_horaab;
    public static javax.swing.JLabel lb_ip;
    public static javax.swing.JLabel lb_ncall;
    public static javax.swing.JLabel lb_nmaq;
    public static javax.swing.JLabel lb_nuser;
    public static javax.swing.JLabel lb_setor;
    public static javax.swing.JLabel lb_status;
    public static javax.swing.JLabel lb_tecabert;
    public static javax.swing.JLabel lb_tecnico;
    public static javax.swing.JLabel lb_tecresp;
    public static javax.swing.JLabel lb_tipop;
    public static javax.swing.JLabel lb_urg;
    public static javax.swing.JTextArea ta_obs;
    private javax.swing.ButtonGroup usb;
    // End of variables declaration//GEN-END:variables

   
    
    public void gravar()
   {
       try
   {
    
           
    //con_hdcli.resultset.first();
   
    
 //código para gravar os dados no banco (dentro do try)
        hd_principal.con_hdserver.executasql("select * from helpdeska where codcalla = "+lb_ncall.getText());
        hd_principal.con_hdserver.resultset.first();
        String nome = "Fechar o Chamado: "+hd_principal.con_hdserver.resultset.getString("codcalla")+"?";
        int opcao_escolhida = JOptionPane.showConfirmDialog(null, nome,"Fechar Chamado ",JOptionPane.YES_NO_OPTION);
        
        if (opcao_escolhida == JOptionPane.NO_OPTION)
        {
            //con_hdserver.executasql("select * from helpdeska");
            //con_hdserver.resultset.first();
           
            //visualizacao(ordenacao);
            navega = 0;
            inicia_combo = 0;
            return ;//caso seja escolhida a opção não excluir, ele
                   // retorna para a posição normal sem executar mais nenhum código
        }
            
        else if (opcao_escolhida == JOptionPane.YES_OPTION)
        {
             
             //java.sql.Date datah;
                
            
            
            
   // Date dataab =con_hdserver.resultset.getDate("dataab");   
    java.util.Date dataf = new java.sql.Date(format.parse(label_data.getText()).getTime());   
    
    GregorianCalendar dataab = new GregorianCalendar();
    dataab.setTime(hd_principal.con_hdserver.resultset.getDate("dataab"));
     
    GregorianCalendar data = new GregorianCalendar();
    data.setTime(dataf);
    
             
    //Calendar xmas = new GregorianCalendar(dataab);
    
   // Calendar newyears = new GregorianCalendar(data);
    
    // Determine which is earlier
    boolean b = dataab.after(data);            // false
    b = dataab.before(data);                   // true
    
    
    // Get difference in milliseconds
    long diffMillis = data.getTimeInMillis()-dataab.getTimeInMillis();
    
    // Get difference in seconds
    //long diffSecs = diffMillis/(1000);           // 604800
    
    // Get difference in minutes
    //long diffMins = diffMillis/(60*1000);        // 10080
    
    // Get difference in hours
    //long diffHours = diffMillis/(60*60*1000);    // 168
    
    // Get difference in days
    long diffDays = diffMillis/(24*60*60*1000);  // 7

             
          
             con_ordena.executasql("select * from helpdeska where urgenciaa like'%"+lb_urg.getText()+"%' and ordem >"+hd_principal.con_hdserver.resultset.getInt("ordem"));   
             con_ordena.resultset.beforeFirst();
             
            java.util.Date dataabertura = new java.sql.Date(format.parse(lb_dataab.getText()).getTime()); 
            
            
            
            mostra_data.le_hora();
            String horaf = mostra_data.hora ;
             
             con_hdsf.executasql("Select * from helpdeskf where nsetor like 'A'");
             String sqlinsert = "insert into helpdeskf (nsetor,nmaq,ipmaq,tipop,descp,data,usuario,tecnico,duracao,tecnicof,horarioa,horariof,dataab) values ('"+
             
             lb_setor.getText()+"','"+
             lb_nmaq.getText()+"','"+ 
             lb_ip.getText()+"','"+
             lb_tipop.getText()+"','"+
             ta_obs.getText()+"','"+
             dataf+"','"+
             lb_nuser.getText()+"','"+
             lb_tecabert.getText()+"','"+
             diffDays+"','"+
             lb_tecresp.getText()+"','"+
             lb_horaab.getText()+"','"+ 
             horaf+"','"+
             dataabertura+"')";
                   
             con_hdsf.statement.executeUpdate(sqlinsert);
            
            String sql = "DELETE from helpdeska Where codcalla ="+lb_ncall.getText();
            int conseguiu_excluir = hd_principal.con_hdserver.statement.executeUpdate(sql);
            if (conseguiu_excluir == 1)
            {
                
                //atualizando o resultset
               hd_principal.con_hdserver.executasql("select * from helpdeska");
               
               hd_principal.con_hdserver.resultset.first();//posiciona no 1º registro
               mostrar_dados();//chama a função que mostra os dados 
              
            }
         }
             
              if(hd_server.lb_ncall.getText().equals(""))
        {
            bt_primeiro.setEnabled(false);
            bt_anterior.setEnabled(false);
            bt_proximo.setEnabled(false);
            bt_ultimo.setEnabled(false);
            bt_atender.setEnabled(false);
            bt_gravar.setEnabled(false);
            bt_trocar.setEnabled(false);
            jm_troca.setEnabled(false);
            jm_salvar.setEnabled(false);
            jm_atend.setEnabled(false);
        }
                
         
            
             while(con_ordena.resultset.next())
             {
                    
                    con_ordatual.executasql("select * from helpdeska where codcalla ="+con_ordena.resultset.getString("codcalla"));
                    con_ordatual.resultset.first();
                    int ordena = con_ordena.resultset.getInt("ordem") - 1;
                    String qusql = "UPDATE helpdeska SET ordem ='"+ordena+"'where codcalla ="+con_ordena.resultset.getString("codcalla");
                    con_ordatual.statement.executeUpdate(qusql); 
                    
                    if(con_ordena.resultset.isLast())
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
             }   
            
             JOptionPane.showMessageDialog(null,"Chamada fechada com sucesso!");

             
 
     }
        catch (ParseException ex) {
            Logger.getLogger(hd_server.class.getName()).log(Level.SEVERE, null, ex);
        }  catch (SQLException erro)
 {
     JOptionPane.showMessageDialog(null,"Erro ao gravar dados!"+erro);
 }
  //pesq = 0;  
  modo_banco = 0;
  
  
  
    lb_tipop.setText("");
    lb_ncall.setText("");
    ta_obs.setText("");
    lb_ip.setText("");
    lb_nmaq.setText("");
    lb_setor.setText("");
    lb_nuser.setText("");
    
    lb_dataab.setText("");
    lb_status.setText("");
    lb_urg.setText("");
    lb_tecresp.setText("");
    
    
   
    
    
    mostrar_dados();
    
    if(hd_server.lb_ncall.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Não há nenhum chamado em aberto!");
        
            bt_primeiro.setEnabled(false);
            bt_anterior.setEnabled(false);
            bt_proximo.setEnabled(false);
            bt_ultimo.setEnabled(false);
            bt_atender.setEnabled(false);
            bt_gravar.setEnabled(false);
            bt_trocar.setEnabled(false);
            jm_troca.setEnabled(false);
            jm_salvar.setEnabled(false);
            jm_atend.setEnabled(false);
        }
    
  travar_campos();
 
       
  
 }



public void travar_campos()
{
    
    
   // bt_gravar.setEnabled(false);
    //jm_salvar.setEnabled(false);
    ta_obs.setEditable(false);
    
    
            
}

public void destrava()
{
    
    //bt_gravar.setEnabled(true);
    //jm_salvar.setEnabled(true);
    ta_obs.setEditable(true);
  
    
}
    



public void lookandfeel()
     
    {
             
         try
        {
            
            UIManager.setLookAndFeel(seta_look);
            SwingUtilities.updateComponentTreeUI(this);
            
        }        
        catch(Exception erro)
        {
            JOptionPane.showMessageDialog(null,erro);
        
        } 
        }   


    
 public static void mostrar_dados()
    {
         try
        {
            
             
  
            
            lb_ncall.setText(hd_principal.con_hdserver.resultset.getString("codcalla"));
            lb_setor.setText(hd_principal.con_hdserver.resultset.getString("nsetora"));
            lb_nmaq.setText(hd_principal.con_hdserver.resultset.getString("nmaqa"));
            lb_ip.setText(hd_principal.con_hdserver.resultset.getString("ipmaqa"));
            lb_tipop.setText(hd_principal.con_hdserver.resultset.getString("tipopa"));
            ta_obs.setText(hd_principal.con_hdserver.resultset.getString("descpa"));
            lb_nuser.setText(hd_principal.con_hdserver.resultset.getString("usuarioa"));
            lb_status.setText(hd_principal.con_hdserver.resultset.getString("status"));
            lb_tecresp.setText(hd_principal.con_hdserver.resultset.getString("tecnico"));
            lb_urg.setText(hd_principal.con_hdserver.resultset.getString("urgenciaa"));
            lb_tecabert.setText(hd_principal.con_hdserver.resultset.getString("tecnicoa"));
            lb_horaab.setText(hd_principal.con_hdserver.resultset.getString("horarioa"));
            dataaberto = "" ;   
            dataaberto = new String( format.format( hd_principal.con_hdserver.resultset.getDate("dataab") ) );
            
            lb_dataab.setText(dataaberto);
            
            
            
            
            if(lb_status.getText().equals("EM ANDAMENTO") && (hd_principal.con_hdserver.resultset.getString("tecnico").equals(lb_tecnico.getText())))
        {
            bt_atender.setEnabled(false);
            bt_gravar.setEnabled(true);
            jm_atend.setEnabled(false);
            jm_salvar.setEnabled(true);
            bt_trocar.setEnabled(true);
            jm_troca.setEnabled(true);
            
        }
          else if(lb_status.getText().equals("NÃO ATENDIDO"))
        {
            bt_atender.setEnabled(true);
            bt_gravar.setEnabled(false);
            jm_atend.setEnabled(true);
            jm_salvar.setEnabled(false);
            bt_trocar.setEnabled(false);
            jm_troca.setEnabled(false);
        }
         else if(lb_status.getText().equals("EM ANDAMENTO") && (! hd_principal.con_hdserver.resultset.getString("tecnico").equals(lb_tecnico.getText())))
         {
            bt_atender.setEnabled(false);
            bt_gravar.setEnabled(false);
            jm_atend.setEnabled(false);
            jm_salvar.setEnabled(false);
            bt_trocar.setEnabled(false);
            jm_troca.setEnabled(false);
            
         }
        }
        catch(SQLException erro)
        {
            if (navega == 1)
            
                JOptionPane.showMessageDialog(null,"Este é o primeiro registro!");
               
            else if (navega == 2)
           
                JOptionPane.showMessageDialog(null,"Este é o último registro!");
                
             else
                //JOptionPane.showMessageDialog(null,"Não localizou dados , é aqui "+erro);
                
            navega = 0;
            
       }
       
         
}
}



      
            

